package com.byedu.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Luo on 2017-08-24.
 */
public class CookieUtil {

    /**
     * 从Cookie缓存中获取Cookie的值
     * @param key
     * @param resquest
     * @return
     */
    public static String get(String key, HttpServletRequest resquest){
        String value = null;
        Cookie[] cookies = resquest.getCookies();

        if( null != cookies && cookies.length > 0 ){
            for (Cookie cookie :cookies){
                if(key.equalsIgnoreCase(cookie.getName())){
                    value = cookie.getValue();
                }
            }
        }
        return  value;
    }
}
